package org.hao.samples.dao;

import java.util.List;

import org.hao.samples.model.ExamUserSubject;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

@Repository
@Transactional
public class UserSubHibernateDAO extends BaseHibernateDAO<ExamUserSubject> implements IUserSubDAO {

	@Override
	public List<ExamUserSubject> findAllUserSub() {
		String hql = "FROM ExamUserSubject";
		return this.find(hql);
	}

	@Override
	public void insertSubjectUsers(ExamUserSubject examUserSubject) {
		this.save(examUserSubject);
	}

	@Override
	public void deleteSubjectUsers(ExamUserSubject examUserSubject) {
		this.delete(examUserSubject);
	}

	@Override
	@SuppressWarnings("unchecked")
	public List<ExamUserSubject> findSubjectUsersById(Integer id) {
		String sql = "from ExamUserSubject as eus where eus.student.user_id =:userId";
		return this.getSession().createQuery(sql).setInteger("userId", id).list();
	}

}
